Obviously, “+'' was chosen to
implement the add operation. We could read the part
``i + j'' as “add the value of j
to the value of i'', thus at
the ADT level this results in
{ Precondition: Let i
= n1 and j
= n2 with n1,
n2 particular Integers
} i.add(j) {
Postcondition: i
= n1 and j
= n2 }
Implementation of ADT: Step 3: add
MODULAR
PROGRAMMING
int i, j, k; /* Define three integers */
i = 1; /* Assign 1 to integer i */
j = 2; /* Assign 2 to integer j */
k = i + j; /* Assign the sum of i and j to k */
Consider the ADT Integer. Outline the relationship
to the ADT Integer in the following
code:
The postcondition ensures
that i and j do not change their values. Please recall the
specification of add. It says that a new Integer is created the value
of which is the sum. Consequently, we must provide a mechanism to access this
new instance.